package com.tanhua.server.controller;


import com.tanhua.model.vo.PageResult;
import com.tanhua.server.server.SmallVideosService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/smallVideos")
@Slf4j
public class SmallVideosController {

    @Autowired
    private SmallVideosService smallVideosService;

    /**
     * 视频上传
     */
    @PostMapping
    public ResponseEntity saveVideo(MultipartFile videoThumbnail, MultipartFile videoFile) throws IOException {
        smallVideosService.saveVideo(videoThumbnail, videoFile);
        return ResponseEntity.ok(null);
    }

    /**
     * 视频列表
     */
    @GetMapping
    public ResponseEntity videosList(@RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pr = smallVideosService.videosList(page, pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 视频用户关注
     */
    @PostMapping("/{id}/userFocus")
    public ResponseEntity userFocus(@PathVariable("id") Long uid) {
        log.info("uid={}", uid);
        smallVideosService.userFocus(uid);
        return ResponseEntity.ok(null);
    }

    /**
     * 视频取消关注用户
     */
    @PostMapping("/{id}/userUnFocus")
    public ResponseEntity userUnFocus(@PathVariable("id") Long uid) {
        log.info("uid={}", uid);
        smallVideosService.userUnFocus(uid);
        return ResponseEntity.ok(null);
    }

    /**
     * 视频点赞
     */
    @PostMapping("/{id}/like")
    public ResponseEntity Focuslike(@PathVariable("id") String uid) {
        log.info("uid={}", uid);
        Integer all = smallVideosService.Focuslike(uid);
        return ResponseEntity.ok(all);
    }

    /**
     * 视频取消点赞
     */
    @PostMapping("/{id}/dislike")
    public ResponseEntity Focusdislike(@PathVariable("id") String uid) {
        log.info("uid={}", uid);
        Integer all = smallVideosService.Focusdislike(uid);
        return ResponseEntity.ok(all);
    }

    /**
     * 查询评论
     *
     * @return
     */
    @GetMapping("/{id}/comments")
    public ResponseEntity comments(@PathVariable("id") String uid,
                                   @RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult resultList = smallVideosService.findFocusd(uid, page, pagesize);
        return ResponseEntity.ok(resultList);
    }

    /**
     * 视频评论点赞
     */
    @PostMapping("/comments/{id}/like")
    public ResponseEntity focusCommentsLike(@PathVariable("id") String id) {
        log.info("id={}", id);
        Integer all = smallVideosService.focusCommentsLike(id);
        return ResponseEntity.ok(all);
    }

    /**
     * 视频评论取消点赞
     */
    @PostMapping("/comments/{id}/dislike")
    public ResponseEntity focusCommentsDislike(@PathVariable("id") String id) {
        log.info("id={}", id);
        Integer all = smallVideosService.focusCommentsDislike(id);
        return ResponseEntity.ok(all);
    }

}
